﻿#region

using System;
using System.Drawing;
using System.Web.UI;
using BusinessLogicLayer;
using BusinessObjects;

#endregion

namespace FastTrackCabService.AdminPanel
{
    public partial class ChangePassword : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void btnReset_OnClick(object sender, EventArgs e)
        {
            txtCurrentPassword.Text = "";
            txtNewPassword.Text = "";
            txtReNewPassword.Text = "";
        }

        protected void btnUpdate_OnClick(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                Administrator administrator = AdministratorBLL.GetAdministrator(Convert.ToInt32(User.Identity.Name));

                var user = new User
                {
                    Username = administrator.UserCredentials.Username,
                    Password = txtCurrentPassword.Text
                };
                if (UserBLL.LoginUser(user))
                {
                    user.Password = txtNewPassword.Text;
                    UserBLL.UpdatePassword(user);
                    lblStatus.Text = "Password successfully updated";
                    lblStatus.ForeColor = Color.Green;
                }
                else
                {
                    lblStatus.Text = "Incorrect Password";
                    lblStatus.ForeColor = Color.Red;
                }
            }
        }
    }
}